package cn.pli.bike.ui;

import android.animation.ValueAnimator;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.LinearInterpolator;

import com.framemodule.BaseApp.AppManager;
import com.framemodule.BaseApp.Setting;
import com.framemodule.base.BaseActivityPresenter;
import com.framemodule.base.netstatus.NetUtils;

import java.util.List;

import cn.bingoogolapple.androidcommon.adapter.BGAOnRVItemClickListener;
import cn.pli.bike.R;
import cn.pli.bike.bean.HttpResult;
import cn.pli.bike.bean.SettingBean;
import cn.pli.bike.bean.UserBean;
import cn.pli.bike.model.UserModel;
import cn.pli.bike.model.subscribers.ProgramSubscriber;
import cn.pli.bike.utils.AppUtils;


public class SettingActivity extends BaseActivityPresenter<SettingDelegate> implements View.OnClickListener {
    private UserBean userBean;
    private static final int CLEAR_CACHE = 0;
    private static final int CHECK_UPDATE = 1;


    @Override
    protected void initModel() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setdata();
        getUserInfo();


    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    @Override
    protected void onNetworkConnected(NetUtils.NetType type) {

    }

    @Override
    protected void onNetworkDisConnected() {

    }

    @Override
    protected void bindEvenListener() {
        super.bindEvenListener();
        viewDelegate.setOnClickListener(this, R.id.iv_title_back, R.id.bt_exit);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {


            case R.id.iv_title_back:
                finish();
                break;
            case R.id.bt_exit:
                AppUtils.clearUserInfo();
                AppManager.getAppManager().AppExit(this, false);

                break;

        }


    }

    private void getUserInfo() {
        UserModel.getAppSetting(new ProgramSubscriber<HttpResult<List<SettingBean>>>() {
            @Override
            public void onNext(HttpResult<List<SettingBean>> listHttpResult) {
                viewDelegate.getUserInfoAdapter().addMoreData(listHttpResult.getData());
            }
        });

    }

    /**
     * 设置数据
     */
    private void setdata() {
        viewDelegate.getUserInfoAdapter().setOnRVItemClickListener(new BGAOnRVItemClickListener() {
            @Override
            public void onRVItemClick(ViewGroup parent, View itemView, int position) {
                if (position == CLEAR_CACHE) {
                   // viewDelegate.toast("清除成功");
                    viewDelegate.showAlert1("清除缓存成功","确定",null);
                    return;
                }
                if (position == CHECK_UPDATE) {
                    viewDelegate.showAlert1("已经是最新版本","确定",null);

                    //viewDelegate.toast("已经是最新版本");
                    return;
                }

                SettingBean setting = viewDelegate.getUserInfoAdapter().getData().get(position);
                Bundle bundle = new Bundle();
                bundle.putString("title", setting.getTitle());
                bundle.putString("url", setting.getUrl());
                readyGo(WebViewActivity.class, bundle);


            }
        });
    }


}
